/*
Realistic Unit Modification v4.0 Dialog 
v4.0.0.1 [ALPHA]
Concept & Development by Draper & Raps | [VRC]
*/

FNC_H_rumTakeOff = {
	_helo = _this select 0;
	_grp = _this select 1;
	_pos = _this select 2;
	_heloPos = getPos _helo;

	_wp = _grp addWaypoint [_pos,0];
	_wp setWaypointType "MOVE";
	_wp setWaypointSpeed "LIMITED";
	_wp setWaypointCompletionRadius 300;
	_helo flyInheight 30;
		
	waitUntil {
		sleep 0.15;
		_dCheck = round(_helo distance _heloPos);
		_dCheck2 = round(_helo distance _heloPos);
		_hCheck = round(getPosATL _helo select 2);
		if (RUM_DEBUG) then {
			hintSilent format[" Distance to WP: %1\n Current Altitude: %2\n Distance from Last WP: %3",_dCheck2,_hCheck,_dCheck];
		};
		if (_dCheck >= 75 && _dCheck < 150 ) then {
			_wp setWaypointSpeed "NORMAL";
			_helo setSpeedMode "NORMAL";
			_helo flyInheight 50;
			true;
		};
	};

	waitUntil {
		sleep 0.15;
		_dCheck = round(_helo distance _heloPos);
		_dCheck2 = round(_helo distance _heloPos);
		_hCheck = round(getPosATL _helo select 2);
		if (RUM_DEBUG) then {
			hintSilent format[" Distance to WP: %1\n Current Altitude: %2\n Distance from Last WP: %3",_dCheck2,_hCheck,_dCheck];
		};
		if (_dCheck >= 150) then {
			_wp setWaypointSpeed "FULL";
			_helo setSpeedMode "FULL";
			_helo flyInheight RUM_THEL_flyHeight;
			true;
		};
	};
};

FNC_H_rumDustOff = {
	_helo = _this select 0;
	_grp = _this select 1;
	_pos = _this select 2;

	_heloPos = getPos _helo;
	
	_wp = _grp addWaypoint [_pos,0];
	_wp setWaypointType "MOVE";
	_wp setWaypointSpeed "LIMITED";
	_wp setWaypointCompletionRadius 300;
	// if (RUM_WorldOverride) then {
		_helo flyInheight 60;
	// } else {
		_helo flyInheight 30;
	// };

	_helo setCombatMode "GREEN";
	_helo setBehaviour "CARELESS";

	waitUntil {
		sleep 0.15;
		_dCheck = round(_helo distance _heloPos);
		_dCheck2 = round(_helo distance _heloPos);
		_hCheck = round(getPosATL _helo select 2);
		if (RUM_DEBUG) then {
			hintSilent format[" Distance to WP: %1\n Current Altitude: %2\n Distance from Last WP: %3",_dCheck2,_hCheck,_dCheck];
		};
		if (_dCheck >= 75 && _dCheck < 200 ) then {
			_wp setWaypointSpeed "NORMAL";
			_helo setSpeedMode "NORMAL";
			_helo flyInheight 55;
			true;
		};
	};

	waitUntil {
		sleep 0.15;
		_dCheck = round(_helo distance _heloPos);
		_dCheck2 = round(_helo distance _heloPos);
		_hCheck = round(getPosATL _helo select 2);
		if (RUM_DEBUG) then {
			hintSilent format[" Distance to WP: %1\n Current Altitude: %2\n Distance from Last WP: %3",_dCheck2,_hCheck,_dCheck];
		};
		if (_dCheck >= 201) then {
			_wp setWaypointSpeed "FULL";
			_helo setSpeedMode "FULL";
			_helo flyInheight RUM_THEL_flyHeight;
			true;
		};
	};
	
	/* remove invisible heli pad used for landing */
	if (!isNil "rumLZPos") then {
		deleteVehicle rumLZPos;
	};
};

FNC_H_ApproachWP = {
	_helo = _this select 0;
	_grp = _this select 1;
	_pos = _this select 2;

	_wp = _grp addWaypoint [_pos,0];
	_wp setWaypointType "MOVE";
	_wp setWaypointSpeed "NORMAL";
	_wp setWaypointCompletionRadius 300;
	_helo flyInHeight 65;

	_helo setCombatMode "GREEN";
	_helo setBehaviour "CARELESS";

	waitUntil {
		sleep 0.15;
		_dCheck = round(_helo distance _pos);
		_hCheck = round(getPosATL _helo select 2);
		if (RUM_DEBUG) then {
			hintSilent format[" Distance to WP: %1\n Current Altitude: %2",_dCheck,_hCheck];
		};
		if (_dCheck <= 200) then {
			_wp setWaypointSpeed "NORMAL";
			_helo setSpeedMode "NORMAL";
			true;
		} else {
			(!alive _helo);
		};
	};
};

FNC_H_rumMoveWP = {
	_helo = _this select 0;
	_grp = _this select 1;
	_pos = _this select 2;

	_wp = _grp addWaypoint [_pos,0];
	_wp setWaypointType "MOVE";
	_wp setWaypointSpeed "FULL";
	// _helo flyInHeight RUM_THEL_flyHeight;
	if(_helo iskindof "Plane")then{
		_wp setWaypointCompletionRadius 1000;
		_helo FlyInHeight RUM_SUP_flyHeightPLN;
	}else{
		_wp setWaypointCompletionRadius 300;
		_helo FlyInHeight RUM_SUP_flyHeight;
	};

	// if (isNil "varRUM_MissionType") then {
		waitUntil {
			sleep 0.15;
			_dCheck = round(_helo distance _pos);
			_hCheck = round(getPosATL _helo select 2);
			if (RUM_DEBUG) then {
				hintSilent format[" Distance to WP: %1\n Current Altitude: %2",_dCheck,_hCheck];
			};
			if (_dCheck >= 800 && _dCheck < 1200) then {
				_wp setWaypointSpeed "FULL";
				_helo flyInHeight 70;
			} else {
					if (_dCheck > 300 && _dCheck < 790) then {
						_wp setWaypointSpeed "NORMAL";
						true;
					};
			};
		};
	// };
};

FNC_H_rumMoveDropWP = {
	_helo = _this select 0;
	_grp = _this select 1;
	_pos = _this select 2;

	_wp = _grp addWaypoint [_pos,0];
	_wp setWaypointType "MOVE";
	_wp setWaypointSpeed "FULL";
	_wp setWaypointCompletionRadius 50;
	_helo flyInHeight 50;

/* 
	waitUntil {
		sleep 0.15;
		_dCheck = round(_helo distance _pos);
		_hCheck = round(getPosATL _helo select 2);
		if (RUM_DEBUG) then {
			hintSilent format[" Distance to WP: %1\n Current Altitude: %2",_dCheck,_hCheck];
		};
		// if (_dCheck < 200) then {
			// true;
		// };
	};
*/
};

FNC_H_rumLandLZ = {
	_helo = _this select 0;
	_grp = _this select 1;
	_pos = _this select 2;

	// Set landing waypoint
	_wp = _grp addWaypoint [_pos,0];
	_wp setWaypointType "MOVE";
	_wp setWaypointSpeed "FULL";
	_wp setWaypointCompletionRadius 400;

	_helo setCombatMode "GREEN";
	_helo setBehaviour "CARELESS";

	waitUntil {
		sleep 0.15;
		_dCheck = round(_helo distance _pos);
		_hCheck = round(getPosATL _helo select 2);
		if (RUM_DEBUG) then {
			hintSilent format[" Distance to WP: %1\n Current Altitude: %2",_dCheck,_hCheck];
		};
		if (_dCheck >= 651 && _dCheck < 1200) then {
			_wp setWaypointSpeed "FULL";
			_helo flyInHeight 60;
		} else {
			if (_dCheck > 150 && _dCheck < 650) then {
				_wp setWaypointSpeed "NORMAL";
				_helo flyInHeight 50;
				// true;
			} else {
				if (_dCheck <= 150) then {
					_wp setWaypointSpeed "LIMITED";
					_helo flyInHeight 50;
					true;
				};
			};
		};
	};

	RUM_THel_land = format["%1",_helo];

	if (RUM_THEL_invisibleH) then {
		rumLZPos = createVehicle ["Land_HelipadEmpty_F", _pos, [], 0, "NONE"];
	};
	
};
FNC_H_rumSpawn = {
	_helo = _this select 0;
	_grp = _this select 1;
	_pos = _this select 2;

	_wp = _grp addWaypoint [_pos,0];
	_wp setWaypointType "MOVE";
	_wp setWaypointSpeed "FULL";
	_wp setWaypointCombatMode "BLUE";
	_wp setWaypointBehaviour "CARELESS";
	_wp setWaypointCompletionRadius 500;
	_helo flyInHeight RUM_THEL_flyHeight;
};

FNC_H_rumUnhookCargo = {
	_helo = _this select 0;
	_grp = _this select 1;
	_pos = _this select 2;

	// Set drop waypoint
	_wp = _grp addWaypoint [_pos,0];
	_wp setWaypointType "MOVE";
	_wp setWaypointSpeed "FULL";
	_wp setWaypointCompletionRadius 400;

	_helo setCombatMode "BLUE";
	_helo setBehaviour "CARELESS";

	waitUntil {
		sleep 0.15;
		_dCheck = round(_helo distance _pos);
		_hCheck = round(getPosATL _helo select 2);
		if (RUM_DEBUG) then {
			hintSilent format[" Distance to WP: %1\n Current Altitude: %2",_dCheck,_hCheck];
		};
		if (_dCheck >= 350 && _dCheck < 900) then {
			_wp setWaypointSpeed "NORMAL";
			_helo flyInHeight 60;
			sleep 1;
		} else {
			if (_dCheck < 350) then {
				_wp setWaypointSpeed "LIMITED";
				_helo flyInHeight 40;
				true;
			};
		};
	};
	_helo flyInHeight 20;
	sleep 3;
	waitUntil {
		(speed _helo) < 10; 
	};
	_helo flyInHeight 15;
	sleep 3;
	_helo flyInHeight 5;
};

FNC_H_rumLandHome = {

	_helo = _this select 0;
	_grp = _this select 1;
	_pos = _this select 2;
	varCPos = _this select 2;

	_wp = _grp addWaypoint [_pos,0];
	_wp setWaypointType "MOVE";
	_wp setWaypointSpeed "NORMAL";
	_wp setWaypointCombatMode "BLUE";
	_wp setWaypointBehaviour "CARELESS";
	_wp setWaypointCompletionRadius 300;
	_helo flyInHeight 40;
	
	waitUntil {
		sleep 0.125;
		_dCheck = round(_helo distance _pos);
		_hCheck = round(getPosATL _helo select 2);
		if (RUM_DEBUG) then {
			hintSilent format[" Distance to WP: %1\n Current Altitude: %2",_dCheck,_hCheck];
		};
		if (_dCheck > 200 && _dCheck <= 400) then {
			_wp setWaypointSpeed "NORMAL";
			_helo flyInHeight 30;
		};
		if (_dCheck <= 200) then {
			_wp setWaypointSpeed "LIMITED";

			/* create invisible heli pad used for landing */
			if (RUM_THEL_invisibleH) then {
					rumLZPos = createVehicle ["Land_HelipadEmpty_F", _pos, [], 0, "NONE"];
			};
			true;
		};
	};
	
	/* lands the helo and shuts engines off */
	_helo land "LAND";

	waitUntil {
		sleep 0.125;
		_dCheck = round(_helo distance _pos);
		_hCheckATL = round(getPosATL _helo select 2);
		_hCheckASL = round(getPosASL _helo select 2);
		if (SurfaceIsWater _pos) then {
			if (RUM_DEBUG) then {
				hintSilent format["Landing on LHD\nDistance to WP: %1\n Current Altitude: %2",_dCheck,_hCheckASL];
			};
			if ((_hCheckASL <= RUM_THEL_CarrierDeck)) then {
				/* ends flight and carries out remaining script commands */
				RUM_THel_endflight = format["%1",_helo];
				true;
			};
		} else {
			if (RUM_DEBUG) then {
				hintSilent format["Landing on Ground\nDistance to WP: %1\n Current Altitude: %2",_dCheck,_hCheckATL];
			};
			if ((_hCheckATL <= 2.5)) then {
				/* ends flight and carries out remaining script commands */
				RUM_THel_endflight = format["%1",_helo];
				true;
			};
		};
	};
};

RUM_THel_moveParaDrop = {
	_mkrname = _this select 0;
	_grp = _this select 1;
	_helo = _this select 2;
	_wpID = _this select 3;
	_pos = getmarkerpos _mkrname;
	_stg = "RUM_THel_land = '"+(format ["%1",_helo]+"'");

	_wpPara =_grp addWaypoint [_pos,100,_wpID];
	_wpPara setWaypointType "MOVE";
	_wpPara setWaypointCombatMode "BLUE";
	_wpPara setWaypointSpeed "NORMAL";
	_wpPara setWaypointBehaviour "CARELESS";
	_wpPara setWaypointCompletionRadius 300;
	_wpPara setWaypointStatements ["true", _stg];
	_helo flyInHeight RUM_THEL_flyHeight;
}; 

FNC_H_rumSpecial_CombatLanding = {
	private ["_combDrop","_helo","_helo_height","_vehCargo","_vehCrew","_crewCount","_uxPlus","_uxMinus","_uyPlus","_uyMinus","_uPos","_hPos","_stg","_stg2"];

	_helo = _this select 0;
	_combDrop = false;
	_vehCargo = [];
	_vehCrew = (_helo getVariable ["_crewVariables",[]] select 1);
	_crewCount = (_helo getVariable ["_crewVariables",[]] select 0);
	
	_vehCargo = ((crew _helo) - _vehCrew);
	_helo land "get out";

	if (!alive _helo) exitwith {};

	while {!_combDrop } do {
		_helo_height =  getPosATL _helo select 2;
		
		if ((round _helo_height) <= 10) then {
			_helo flyinheight 2.55;
			_helo domove getPosATL _helo;
			_combDrop = true;
		};
		if (RUM_DEBUG) then {
			hintsilent format ["%1's current altitude is: %2\nCrew Count: %3\nPassenger Count:%4",_helo, _helo_height,_crewCount,(count (crew _helo) - _crewCount)];
		};
		sleep 0.5;
	};

	waitUntil {
		sleep 0.25;
		_helo_height = getPosATL _helo select 2;
		if ((typeOf _helo == "Heli_Light_01_base_F")) then {
			(_helo_height <= 2.7);
		} else {
			(_helo_height <= 3.7);
		};
	};
	
	_hPos = position (vehicle player);
	{
		[_x] orderGetIn false;
		unassignVehicle _x;
		_uxPlus = floor(random 10);
		_uxMinus = floor(random 10);
		_uyPlus = floor(random 10);
		_uyMinus = floor(random 10);
		_uPos = [(_hPos select 0) + _uxPlus - _uxMinus,(_hPos select 1) + _uyPlus - _uyMinus,0];
		_x doMove _uPos;
	} foreach _vehCargo;

	if ((_helo isKindOf "kyo_MH47E_base")/* add more walkable helo's here */) then {
		_stg = format ["%1 : Move On!",_callsign];
		_stg2 = format ["%1 : Abort, RTB!",_callsign];
		_helo setVariable ["RUM_THel_continue",false,true];
		if (alive _helo) then {
			RUM_THel_actionid = player addAction [_stg, (RUM_PATH+"Transport\om.sqf"),[_helo,_callsign],1,false,true,"","_this == vehicle _this;"];
			RUM_THel_actionid2 = _helo addAction [_stg, (RUM_PATH+"Transport\om.sqf"),[_helo,_callsign],1,false,true,"","_this in _target"];
			// RUM_THel_actionid3 = player addAction [_stg2, (RUM_PATH+"Transport\abort.sqf"),[_arry]];
		};
		waitUntil {
			sleep 0.15;
			((!alive _helo) || (_helo getVariable "RUM_THel_continue"));
		};
	} else {
		waitUntil {
			sleep 0.25;
			if (RUM_DEBUG) then {
				hintsilent format ["%1 crew in %2",(count crew _helo), _helo];
			};
			if ((count(crew _helo) <= _crewCount)) then {
				if (RUM_DEBUG) then {
					hintsilent format ["There are %1 crew in %2, moving out.",(count crew _helo), _helo];
				};
				sleep 2;
				_helo setVariable ["RUM_THel_continue",true,true];
			} else {
				if (RUM_DEBUG) then {
					hintsilent "Holding till troops have disembarked";
				};
			};
			(!alive _helo) || (_helo getVariable "RUM_THel_continue");
		};
	};
};

FNC_H_rumEndMission = {

	_helo = _this select 0;
	_home = _this select 1;
	_pilot = _this select 2;
	_vehCrew = (_helo getVariable ["_crewVariables",[]] select 1);	
	_helo addEventHandler ["HandleDamage", {false}];

	/* unlocks the vehicle positions */
	_helo lockDriver false; // Pilot
	_helo lockTurret [[0], false]; // Co-Pilot
	_helo lockTurret [[1], false]; // Gunner1 - if the vehicle has this position
	_helo lockTurret [[2], false]; // Gunner2 - if the vehicle has this position


	/* empty fuel from helo to keep it on the ground in case of idiot AI pilot */
	_helo setFuel 0;
	sleep 2;

	/* delete all the markers that were created for this instance. */
	_mkrname1 = format ["%1ingress",_helo];
	_mkrname2 = format ["%1target",_helo];
	_mkrname3 = format ["%1egress",_helo];
	_mkrname4 = format ["%1ingress2",_helo];
	_mkrname5 = format ["%1target2",_helo];
	_mkrname6 = format ["%1egress2",_helo];
	deletemarkerLocal _mkrname1;
	deletemarkerLocal _mkrname2;
	deletemarkerLocal _mkrname3;
	deletemarkerLocal _mkrname4;
	deletemarkerLocal _mkrname5;
	deletemarkerLocal _mkrname6;

	if (alive _helo) then {
		sleep 1;

		/* turn helos engines off  */
		_pilot action ["engineOff", _helo];

		/* gets all crew out of helo and delete all crew members */
		{
			unassignVehicle _x;
			_x action ["GETOUT",_helo];
			sleep 1.25;
			deleteVehicle _x;
		} forEach _vehCrew;

		/* set the helo back in the correct position and direction */
		_helo setdir getdir _home;

		/* repairs, rearms and refuels the helo */
		_helo setDamage 0;
		_helo setFuel 1;
		
		/* if there are weapons present, this will rearm the helo */
		_mags = magazinesAmmo _helo;
		// _mags = getArray (configFile>>"cfgVehicles">>typeOf _helo>>"Turrets">>"MainTurret">>"magazines");
		{_helo removeMagazine _x} forEach magazines _helo;
		{_helo addMagazine _x} forEach _mags;
	};

	/* delete the invisible helo pad used for location landing */
	if (!isNil "rumLZPos") then {
		deleteVehicle rumLZPos;
	};
};

FNC_H_rumEndMissionSpawn = {

	_helo = _this select 0;
	_spwn = _this select 1;
	_pilot = _this select 2;
	_wpArray = _this select 3;
	_vehCrew = (_helo getVariable ["_crewVariables",[]] select 1);	
	_helo addEventHandler ["HandleDamage", {false}];

	/* unlocks the vehicle positions */
	_helo lockDriver false; // Pilot
	_helo lockTurret [[0], false]; // Co-Pilot
	_helo lockTurret [[1], false]; // Gunner1 - if the vehicle has this position
	_helo lockTurret [[2], false]; // Gunner2 - if the vehicle has this position


	/* empty fuel from helo to keep it on the ground in case of idiot AI pilot */
	_helo setFuel 0;
	sleep 2;

	/* delete all the markers that were created for this instance. */
	{
		deletemarkerLocal _x;
	} forEach _wpArray;

	/* gets all crew out of helo and delete all crew members */
	{
		unassignVehicle _x;
		_x action ["GETOUT",_helo];
		sleep 1.25;
		deleteVehicle _x;
	} forEach _vehCrew;

	sleep 1;
	deleteVehicle _helo;

	/* delete the invisible helo pad used for location landing */
	if (!isNil "rumLZPos") then {
		deleteVehicle rumLZPos;
	};
};

FNC_H_rumVehicleOptions = {
	// options for the vehicles to open doors and lower ramps based on speed and altitude settings.
	private ["_veh","_alt","_speed"];
	_veh = _this select 0;

	switch (typeof _veh) do {

		/* UH-80 Ghost Hawk */
		case "B_Heli_Transport_01_F": {
			while {alive _veh} do {
				sleep 0.5;
				_alt = getPos _veh select 2;
				_speed = (sqrt ((velocity _veh select 0)^2 + (velocity _veh select 1)^2 + (velocity _veh select 2)^2));
				if ((_alt < 6) && (_speed < 12)) then {
					_veh animateDoor ['door_R',1]; 
					_veh animateDoor ['door_L',1];
				} else {
					_veh animateDoor ['door_R',0]; 
					_veh animateDoor ['door_L',0];
				};
			};
		};

		/* UH-80 Ghost Hawk (Camo) */
		case "B_Heli_Transport_01_camo_F": {
			while {alive _veh} do {
				sleep 0.5;
				_alt = getPos _veh select 2;
				_speed = (sqrt ((velocity _veh select 0)^2 + (velocity _veh select 1)^2 + (velocity _veh select 2)^2));
				if ((_alt < 6) && (_speed < 12)) then {
					_veh animateDoor ['door_R',1]; 
					_veh animateDoor ['door_L',1];
				} else {
					_veh animateDoor ['door_R',0]; 
					_veh animateDoor ['door_L',0];
				};
			};
		};

		/* CH-49 Mohawk */
		case "I_Heli_Transport_02_F": {
			while {alive _veh} do {
				sleep 0.5;
				_alt = getPos _veh select 2;
				_speed = (sqrt ((velocity _veh select 0)^2 + (velocity _veh select 1)^2 + (velocity _veh select 2)^2));
				if ((_alt < 4) && (_speed < 12)) then {
					_veh animateDoor ['door_back_R',1]; 
					_veh animateDoor ['door_back_L',1];
					_veh animate ['CargoRamp_Open',1];
				} else {
					_veh animateDoor ['door_back_R',0]; 
					_veh animateDoor ['door_back_L',0];
					_veh animate ['CargoRamp_Open',0];
				};
			};
		};
		/* Mi-48 Kajman */
		case "O_Heli_Attack_02_F": {
			while {alive _veh} do {
				sleep 0.5;
				_alt = getPos _veh select 2;
				_speed = (sqrt ((velocity _veh select 0)^2 + (velocity _veh select 1)^2 + (velocity _veh select 2)^2));
				if ((_alt < 4) && (_speed < 12)) then {
					_veh animateDoor ['door_R',1]; 
					_veh animateDoor ['door_L',1];
				} else {
					_veh animateDoor ['door_R',0]; 
					_veh animateDoor ['door_L',0];
				};
			};
		};

		/* Mi-48 Kajman (Black) */
		case "O_Heli_Attack_02_black_F": {
			while {alive _veh} do {
				sleep 0.5;
				_alt = getPos _veh select 2;
				_speed = (sqrt ((velocity _veh select 0)^2 + (velocity _veh select 1)^2 + (velocity _veh select 2)^2));
				if ((_alt < 4) && (_speed < 12)) then {
					_veh animateDoor ['door_R',1]; 
					_veh animateDoor ['door_L',1];
				} else {
					_veh animateDoor ['door_R',0]; 
					_veh animateDoor ['door_L',0];
				};
			};
		};

		/* MH-47E Base */
		case "kyo_MH47E_base": {
			while {alive _veh} do {
				sleep 0.5;
				_alt = getPos _veh select 2;
				_speed = (sqrt ((velocity _veh select 0)^2 + (velocity _veh select 1)^2 + (velocity _veh select 2)^2));
				if ((_alt < 4) && (_speed < 12)) then {
					sleep 5;
					_veh animate ["Ani_Ramp",0];
					_veh animate ["Ani_Hatch1", 1];
					_veh animate ["Ani_Hatch2", 1];
				} else {
					_veh animate ["Ani_Ramp",1]; 
				};
			};
		};

		/* MH-47E Level Ramp */
		case "kyo_MH47E_Ramp": {
			while {alive _veh} do {
				sleep 0.5;
				_alt = getPos _veh select 2;
				_speed = (sqrt ((velocity _veh select 0)^2 + (velocity _veh select 1)^2 + (velocity _veh select 2)^2));
				if ((_alt < 4) && (_speed < 12)) then {
					sleep 5;
					_veh animate ["Ani_Ramp",0];
					_veh animate ["Ani_Hatch1", 1];
					_veh animate ["Ani_Hatch2", 1];
				} else {
					_veh animate ["Ani_Ramp",1]; 
				};
			};
		};

		/* MH-47E Hard Core */
		case "kyo_MH47E_HC": {
			while {alive _veh} do {
				sleep 0.5;
				_alt = getPos _veh select 2;
				_speed = (sqrt ((velocity _veh select 0)^2 + (velocity _veh select 1)^2 + (velocity _veh select 2)^2));
				if ((_alt < 4) && (_speed < 12)) then {
					sleep 5;
					_veh animate ["Ani_Ramp",0];
					_veh animate ["Ani_Hatch1", 1];
					_veh animate ["Ani_Hatch2", 1];
				} else {
					_veh animate ["Ani_Ramp",1]; 
				};
			};
		};

		/* CH-67E Huron */
		case "B_Heli_Transport_03_unarmed_F": {
			while {alive _veh} do {
				sleep 0.5;
				_alt = getPos _veh select 2;
				_speed = (sqrt ((velocity _veh select 0)^2 + (velocity _veh select 1)^2 + (velocity _veh select 2)^2));
				if ((_alt < 4) && (_speed < 12)) then {
					sleep 5;
					_veh animateDoor ['Door_rear_source', 1];
				} else {
					_veh animateDoor ['Door_rear_source', 0]; 
				};
			};
		};

		/* MV-22 */
		case "MV22": {
			while {alive _veh} do {
				sleep 0.5;
				_alt = getPos _veh select 2;
				_speed = (sqrt ((velocity _veh select 0)^2 + (velocity _veh select 1)^2 + (velocity _veh select 2)^2));
				if ((_alt < 4) && (_speed < 12)) then {
					_veh animate ["ramp_top",1]; 
					_veh animate ["ramp_bottom",1];
					sleep 3;
					_helo animate ["door1_top", 1];
					_helo animate ["door1_bottom", 1];
				} else {
					_veh animate ["ramp_top",0]; 
					_veh animate ["ramp_bottom",0];
					sleep 3;
					_helo animate ["door1_top", 0];
					_helo animate ["door1_bottom", 0];
				};
			};
		};
	}; 	
};

